<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>Title</title>

    <script type="text/javascript" src="js/jquery-1.8.0.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#ch_checkall,#top_ch_checkall").click(function () {
                if (this.checked) {
                    $("input[name=ck_id]").attr("checked", "checked");
                } else {
                    $("input[name=ck_id]").removeAttr("checked");
                }
            });

            $("table tr").mouseover(function () {
                $(this).css("background", "#D3EAEF");
                $(this).siblings().css("background", "white");
            });
        });

        function delMuti(){
            //判断用户至少选了一项
            if($("input[name=ck_id]:checked").size()==0){
                alert("请至少选一项!");
            }
            else{
                if(confirm('确定要删除所选项吗')){
                    document.form1.submit();
                }
            }
        }
        function del(id){
            var currentAdminId=${admin.id};
            if(confirm('确定要删除吗')){
                    if(currentAdminId==id){
                        alert("不能删除自已!");
                    }
                    else{
                        window.location.href="AdminServlet.do?flag=del&id="+id;
                    }
                }
        }
        function subForm(pageIndex) {
            document.form1.action= "AdminServlet.do?flag=manage&pageIndex=" + pageIndex;
            document.form1.submit();
        }
        function subForm1() {
            var pageIndex=document.getElementById("pageIndex").value;
            subForm(pageIndex);
        }
        function lock(item,id,pageIndex){
            var msg;
            if(item==true){
                msg="确定要锁定吗";
            }
            if(item==false){
                msg="确定要解锁吗";
            }
            if(confirm(msg)){
                $("#lock").attr("href","AdminServlet.do?flag=lock&id="+id+"&pageIndex="+pageIndex+"&item="+item);
            }else{
                return false;
            }
        }
    </script>
    <link rel="stylesheet" type="text/css" href="css/maintable.css" />
    <style>
        .note{
            max-width: 50px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        #adminName{
            width: 200px;
        }
    </style>
</head>
<body>

<div class ="div_title">
    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
    <div class="div_titleoper">
        <input type="checkbox" id="top_ch_checkall"/> 全选 <a href="admin/admin_add.jsp"> <img src="images/add.gif"/>添加 </a> <a href="javascript:delMuti()"><img src="images/del.gif"/>删除</a> </div>
</div>
<form action="AdminServlet.do"  name="form1" method="post">
    <input type="hidden" name="flag" value="delAdmin" />
    <table class="main_table" >
        <tr>
            <th><input type="checkbox" id="ch_checkall" /></th>	<th>账号</th> 	<th>状态</th>	<th>备注</th>  <th>最后更新日期</th> 	<th>操作</th>
        </tr>

        <c:forEach var="admin" items="${adminList}" >
            <tr>
                <td>
                    <input type="checkbox" name="ck_id" value="${admin.id}" />
                </td>
                <td id="adminName">${admin.adminName}</td>
                <td>
                    <c:choose>
                        <c:when test="${admin.state==2}">已锁定</c:when>
                    </c:choose>
                </td>
                <td class="note"> <a  title="${admin.note}">${admin.note}</a> </td>
                <td><a>${admin.editDate}</a></td>
                <td>
                    <c:if test="${admin.state=='2'}">
                        <a href="AdminServlet.do" id="lock" onclick="return lock(false,${admin.id},${pageInfo.pageIndex})">解锁</a>
                    </c:if>
                    <c:if test="${admin.state=='1'}">
                        <a href="AdminServlet.do" id="lock" onclick="return lock(true,${admin.id},${pageInfo.pageIndex})">锁定</a> |
                    </c:if>
                    <c:if test="${admin.state=='1'}">
                        <a href="AdminServlet.do?flag=update&id=${admin.id}">修改</a> |
                    </c:if>

                    <a href="javascript:del(${admin.id })">删除</a>

                </td>
            </tr>
        </c:forEach>

    </table>
</form>
<div class="div_page" >
    <div class="div_page_left">    共有 <label>${pageInfo.rowCount }</label> 条记录，当前第 <label>${pageInfo.pageIndex }</label> 页，共 <label>${pageInfo.pageCount }</label> 页	</div>

    <div class="div_page_right" >
        <c:choose>

            <c:when test="${pageInfo.hasUp }" >
                <button onclick="subForm(1)" >首页</button>
                <button onclick="subForm(${pageInfo.pageIndex-1})">上一页</button>
            </c:when>

            <c:otherwise>
                首页
                上一页
            </c:otherwise>

        </c:choose>

        <c:choose>

            <c:when test="${pageInfo.hasNext}" >
                <button onclick="subForm(${pageInfo.pageIndex+1})">下一页</button>
                <button onclick="subForm(${pageInfo.pageCount})">尾页</button>
            </c:when>

            <c:otherwise>
                下一页
                尾页
            </c:otherwise>
        </c:choose>

        <button onclick="subForm1()">转到</button>
        <input type="text" name="pageIndex" id="pageIndex" value="${pageInfo.pageIndex }" /> 页
    </div>

</div>
</body>
</html>
